package cn.edu.cug.cs.gtl.plugins.catalog.tree;

import cn.edu.cug.cs.gtl.apis.ui.AbstractApplication;
import cn.edu.cug.cs.gtl.apis.ui.actions.AbstractAction;
import cn.edu.cug.cs.gtl.apis.ui.datake.DatakeApp;
import cn.edu.cug.cs.gtl.apis.ui.datake.DatakeFrame;
import cn.edu.cug.cs.gtl.apis.ui.datake.catalogtree.CatalogTree;

import java.awt.event.ActionEvent;
import java.util.Locale;
import java.util.ResourceBundle;

public class AddExistItemAction extends AbstractAction {
    @Override
    public void initialize(AbstractApplication theApp) {
        this.theApp = theApp;
        ResourceBundle resourceBundle = ResourceBundle.getBundle("catalog-resource", Locale.getDefault());

        name = resourceBundle.getString("popupmenu.catalog.tree.add_exist_item");
        menuItem.setText(name);
        menuItem.addActionListener(this);
        ((CatalogTree) (getDatakeFrame().getCatalogPanel().getTreeComponent())).getGroupNodePopupMenu().add(menuItem);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        CatalogTree tree = (CatalogTree) getDatakeFrame().getCatalogPanel().getTreeComponent();
        new DBQueryDataItemDialog(tree);
    }

    public DatakeFrame getDatakeFrame() {
        return (DatakeFrame) (((DatakeApp)theApp).getMainFrame());
    }
}
